function httpRequest($api, $data_string) {
  $ch = curl_init($api);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
  curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_HTTPHEADER, array(
      'Content-Type: application/json',
      'Content-Length: ' . strlen($data_string))
  );
  $result = curl_exec($ch);
  curl_close($ch);
  return json_decode($result, true);
}
將以下資料變成 json 格式傳輸傳給對方接應的 <https-api-url>
$data = array(
    "id" => $id,
    "field" => $field
);
$data = httpRequest('<https-api-url>', json_encode($data));
要印出對方回的 json key and value 內容時
echo $data['message'];
如果對方回的是 json array,使用 foreach 接應即可
就能夠印出迴圈,對方回傳多少筆就印多少筆
foreach ($data as $value) {
    echo $value['message'];
}
可以使用 sizeof 查看 object 的長度,輕鬆做判斷
echo sizeof($data); // int
如果對方回的不是 json 只是直接傳 body 過來
將上面的 function 中的
return json_decode($result, true);
#改為
return $result;
然後直接印出即可
echo $data;